
const {
  getShopList
} = require("../../api/index")
Page({
  /** 
   * 页面的初始数据 
   */
  data: {
    navList: [],
    toView: 'inToView01',
    currentActiveIndex:0
  },
  //跳转详情
  goDetail: (e) => {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/detail_zjg/index?id=' + id
    })
  },
  currentActiveIndex: function (e) {
    console.log(e,"123");
    let _id = e.target.dataset.id;
    // console.log(_id);
    var id = e.currentTarget.dataset.id;
    console.log(id);
    this.setData({
      currentActiveIndex: id,
      toView: 'inToView' + _id
    })
  },
  onLoad: function (e) {
    getShopList().then(res => {
      let newArr = [];
      //获取一级数据
      console.log(res,'newArr')
      newArr = res.data.data.data.filter((item) => item.level === "1")
      
      //从一级数据里获取二级数据children
      newArr = newArr.map((item) => {
        return {
          ...item,
          children: res.data.data.data.filter((val) => val.parentCode === item.code),
        }
      })
      //从二级数据里获取三级数据
      newArr = newArr.map((item) => {
        return {
          ...item,
          children: item.children.map((val) => {
            return {
              ...val,
              children: res.data.data.data.filter((v) => v.parentCode === val.code)
            }
          })
        }
      })
      this.setData({
        // 将数据赋给原定义的空数组
        navList: [...newArr]
      })
    })
  }
})